﻿"""测试单选框"""
import tkinter as tk
from tkinter import messagebox
from PIL import Image, ImageTk


class Application(tk.Frame):  # Application是应用的含义，需要继承Frame的初始化
    """一个经典的GUI程序的类的写法"""

    def __init__(self, master=None):  # 要传递master
        super().__init__(master)
        self.master = master
        self.pack()  # 通过布局管理显示
        self.create_widget()  # 调用类函数进行初始化小部件

    def create_widget(self):  # Widget是小部件的含义
        self.codeHobby = tk.IntVar()
        self.videoHobby = tk.IntVar()

        print(self.codeHobby.get())  # 默认值是0
        self.choose_codeHobby = tk.Checkbutton(self.master, text='敲代码',
                                               variable=self.codeHobby, onvalue=1,
                                               offvalue=0)
        self.choose_videoHobby = tk.Checkbutton(self.master, text='看视频',
                                                variable=self.videoHobby, onvalue=1,
                                                offvalue=0)
        self.choose_codeHobby.pack(side='left')
        self.choose_videoHobby.pack(side='left')
        tk.Button(self.master, command=self.confirm, text='确定').pack(side='left')



    def confirm(self):
        if self.videoHobby.get()==1:
            messagebox.showinfo('测试', '看视频，都是正常人有的爱好！你喜欢看什么类型?')
        if self.codeHobby.get()==1:
            messagebox.showinfo('测试', '抓获野生程序猿一只，赶紧送他视频')





def main():
    root = tk.Tk()
    root.geometry("800x500+200+300")
    root.title("测试label标签")
    app = Application(master=root)
    root.mainloop()


if __name__ == '__main__':
    main()
